package com.songmy.spider.run.my;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.alibaba.fastjson.JSONObject;
import com.songmy.spider.callback.HttpXmlClient;
import com.songmy.spider.run.vo.SpiderRule;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/***
 * 回调内容
 * @author Marc
 * @version 1.0
 */
public class CallBackPipeline implements Pipeline {
	SpiderRule rule = null ;
	
	public CallBackPipeline(SpiderRule rule ) {
		this.rule = rule ; 
	}
	
	final static String _VALUE = "_VALUE";
	
	public void process(ResultItems resultItems, Task task) {
		JSONObject o = new JSONObject();

		UUID uuid = UUID.randomUUID();  
		o.put("site", task.getSite().getDomain());
		o.put("uuid", task.getUUID());
		o.put("guid", uuid);
		o.put(_VALUE, resultItems.get(_VALUE));
		
		Map<String, String> params = new HashMap<String, String>();
		params.put("callBack", o.toString());
		HttpXmlClient.post(rule.getCallBack(), params);
	}

}
